package org.yx.service.smfr.view_production_order;

import java.util.ArrayList;
import java.util.List;

import org.dbist.dml.Page;
import org.dbist.dml.Query;
import org.yx.models.SbasProdMat;
import org.yx.models.SmfrOrdDef;
import org.yx.utils.BaseService;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 查询生产订单信息
 *
 * @author zxw
 * @since 2018/04/19
 **/
public class SmfrViewProductionOrderService extends BaseService {
    public SmfrViewProductionOrderOut viewProductionOrder(SmfrViewProductionOrderIn in) throws Exception {
        Query query = new Query(in.getPageIndex(), in.getPageSize());
        query.addFilter("orgCode", in.getUserOrgCode());
        if (StrUtil.isNotBlank(in.getMo())) {
            query.addFilter("mo", in.getMo());
        }
        if (StrUtil.isNotBlank(in.getMatCode())) {
            query.addFilter("matCode", in.getMatCode());
        }
        if(StrUtil.isNotBlank(in.getErpOrderNo())){
            query.addFilter("erpOrderNo",in.getErpOrderNo());
        }
        if (StrUtil.isNotBlank(in.getMoStatus())) {
            query.addFilter("moStatus", in.getMoStatus());
        }
        if (in.getPlanStartTime() != null) {
            query.addFilter("planStartTime", in.getPlanStartTime());
        }
        if (in.getPlanEndTime() != null) {
            query.addFilter("planEndTime", in.getPlanEndTime());
        }
        //query.addOrder("updateDate", false);

		/*
        List<SmfrOrdDef> ordList = selectList(SmfrOrdDef.class, query);
        List<ProductionOrder> orders = new ArrayList<ProductionOrder>();
        for (SmfrOrdDef order : ordList) {
            ProductionOrder mo = new ProductionOrder();
            copyProperties(order, mo);

            SbasProdMat prod = selectOne(SbasProdMat.class, in.getUserOrgCode(), mo.getMatCode(), mo.getMatVer());
            if (prod != null) {
                mo.setMatDesc(prod.getMatDesc());
                mo.setMatSpec(prod.getMatSpec());
                mo.setUnit(prod.getUnit());
            }
            orders.add(mo);
        }
		*/

        SmfrViewProductionOrderOut out = new SmfrViewProductionOrderOut();
        Page<ProductionOrder> orderPage = selectPageBySqlFilePath("select_work_order", query, ProductionOrder.class);
        out.setOrderList(orderPage.getList());
        out.setTotal(orderPage.getTotalSize());

        return out;
    }
}